package dao

import (
	"family/model"
	"family/pkg/db"
)

var PeopleDao = new(peopleDao)

type peopleDao struct{}

func (*peopleDao) Create(people *model.People) error {
	people.ID = db.GetId()
	return db.DB.Create(&people).Error
}

func (*peopleDao) Page(id uint64) ([]*model.People, int64, error) {
	var people []*model.People
	var total int64
	result := db.DB.Where(&model.People{ID: id}).Find(&people)
	if result.Error != nil {
		return nil, 0, result.Error
	}
	return people, total, nil
}

func (*peopleDao) Info(id string) (*model.People, error) {
	var people model.People
	err := db.DB.First(&people, id).Error
	if err != nil {
		return nil, err
	}
	return &people, nil
}

func (*peopleDao) Update(people *model.People) error {
	return db.DB.Model(&people).Updates(&people).Error
}

func (*peopleDao) Delete(ids []string) error {
	var people model.People
	return db.DB.Delete(&people, ids).Error
}
